package user_api

import (
	"github.com/gogf/gf/frame/g"
)

// 子用户模块
const (
	OPEN_API_CHILD_NAME_SHOW                   = "user.child.show"
	OPEN_API_CHILD_NAME_LIST                   = "user.child.list"
	OPEN_API_CHILD_NAME_CREATE                 = "user.child.create"
	OPEN_API_CHILD_NAME_UPDATE                 = "user.child.update"
	OPEN_API_CHILD_NAME_DELETE                 = "user.child.delete"
	OPEN_API_CHILD_NAME_PASSWORD               = "user.child.password"
	OPEN_API_CHILD_NAME_ACCESSES               = "user.child.accesses"
	OPEN_API_CHILD_NAME_ACCESSES_SAVE          = "user.child.accesses.save"
	OPEN_API_CHILD_NAME_LIST_BY_TYPE           = "user.child.list.by.type"
	OPEN_API_CHILD_NAME_LIST_BY_MASTER         = "user.child.list.by.master"
	OPEN_API_CHILD_NAME_FIND_BY_NAME           = "user.child.master.name"
	OPEN_API_CHILD_NAME_CHILD_OPERATE          = "user.child.operate"
	OPEN_API_CHILD_NAME_CHECK_REAL_INFORMATION = "user.child.realInformation.check"
	OPEN_API_CHILD_NAME_SAVE_REAL_INFORMATION  = "user.child.realInformation.save"
)

// 检查系统实名制问题
func CheckRealInformation(uid string) string {
	return CallApi(OPEN_API_CHILD_NAME_CHECK_REAL_INFORMATION, g.Map{
		"uid": uid,
	})
}

// 新增用户实名信息
func SaveRealInformation(params map[string]interface{}) string {
	return CallApi(OPEN_API_USER_NAME_CREATE, g.Map{
		"master_user_id":   params["master_user_id"],
		"uid":              params["uid"],
		"name":             params["name"],
		"password":         params["password"],
		"qq":               params["qq"],
		"mobile":           params["mobile"],
		"bind_operator_id": params["bind_operator_id"],
	})
}

// 查询指定用户，根据用户ID
func FindById(id string) string {
	return CallApi(OPEN_API_CHILD_NAME_SHOW, g.Map{
		"api_uri_placeholder_values": g.Map{
			"id": id,
		},
	})
}

// 查询指定子用户，根据用户邮箱
func FindByChildName(params map[string]interface{}) string {
	return CallApi(OPEN_API_CHILD_NAME_FIND_BY_NAME, g.Map{
		"masterUserId":      params["masterUserId"],
		"name":              params["name"],
		"isAuthorization":   params["isAuthorization"],
		"masterUserChildId": params["masterUserChildId"],
		"userInfo":          params["userInfo"],
		"password":          params["password"],
	})
}

// 获取子用户信息
func ListByMaster(id, page, pageNum, masterUserChildId string) string {
	return CallApi(OPEN_API_CHILD_NAME_LIST_BY_MASTER, g.Map{
		"api_uri_placeholder_values": g.Map{
			"masterUserId": id,
		},
		"masterUserChildId": masterUserChildId,
		"page":              page,
		"pageNum":           pageNum,
	})
}

// 获取用户列表(根据用户类型)
func ListByType(id, page, pageNum, t string) string {
	return CallApi(OPEN_API_CHILD_NAME_LIST_BY_TYPE, g.Map{
		"api_uri_placeholder_values": g.Map{
			"masterUserId": id,
		},
		"type":    t,
		"page":    page,
		"pageNum": pageNum,
	})
}

// 获取子用户列表
func GetChildUserList(params map[string]interface{}) string {
	return CallApi(OPEN_API_CHILD_NAME_LIST, params)
}

// 创建子用户
func CreateChildUser(params map[string]interface{}) string {
	return CallApi(OPEN_API_CHILD_NAME_CREATE, g.Map{
		"master_user_id": params["master_user_id"],
		"name":           params["name"],
		"note":           params["note"],
		"password":       params["password"],
		"type":           params["type"],
		"ext":            params["ext"],
		"detail":         params["detail"],
		"status":         params["status"],
	})
}

// 编辑子用户
func UpdateChildUser(id string, params map[string]interface{}) string {
	return CallApi(OPEN_API_CHILD_NAME_UPDATE, g.Map{
		"api_uri_placeholder_values": g.Map{
			"id": id,
		},
		"name":   params["name"],
		"note":   params["note"],
		"ext":    params["ext"],
		"status": params["status"],
	})
}

// 删除子用户
func DeleteChildUser(id string) string {
	return CallApi(OPEN_API_CHILD_NAME_DELETE, g.Map{
		"api_uri_placeholder_values": g.Map{
			"id": id,
		},
	})
}

// 重置子用户密码
func ResetChildPassword(id string, params map[string]interface{}) string {
	return CallApi(OPEN_API_CHILD_NAME_PASSWORD, g.Map{
		"api_uri_placeholder_values": g.Map{
			"id": id,
		},
		"password":              params["password"],
		"password_current":      params["password_current"],
		"password_confirmation": params["password_confirmation"],
	})
}

// 获取子用户分组权限
func GetChildGroupAccesses(id string, perLine int) string {
	return CallApi(OPEN_API_CHILD_NAME_ACCESSES, g.Map{
		"api_uri_placeholder_values": g.Map{
			"id": id,
		},
		"perLine": perLine,
	})
}

// 获取子用户分组权限
func SaveChildGroupAccesses(id, t string, params map[string]interface{}) string {
	return CallApi(OPEN_API_CHILD_NAME_ACCESSES_SAVE, g.Map{
		"api_uri_placeholder_values": g.Map{
			"id":   id,
			"type": t,
		},
	})
}

// 子用户操作相关
func OperateChild(id, methodId, masterUserChildId string, params map[string]interface{}) string {
	return CallApi(OPEN_API_CHILD_NAME_CHILD_OPERATE, g.Map{
		"api_uri_placeholder_values": g.Map{
			"id":   id,
			"type": methodId,
		},
		"masterUserChildId": masterUserChildId,
		"serviceFlag":       params["serviceFlag"],
		"expiredAt":         params["expiredAt"],
		"levelId":           params["levelId"],
		"system":            params["system"],
	})
}
